package com.test.controller;

import com.github.pagehelper.PageInfo;
import com.test.entity.Adminuser;
import com.test.service.AdminuserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/admin/adminUser")
@Api("管理员")
public class AdminUserController {

    @Autowired
    AdminuserService adminuserService;


    @RequestMapping(value = "getAdminUserList", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation("获取管理员列表")
    public String getUserList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                              Adminuser adminuser,
                              Model model) {
        PageInfo<Adminuser> AdminuserListPage = adminuserService.queryByPage(adminuser, pageNum, pageSize);
        model.addAttribute("userListPage", AdminuserListPage);
        return "adminUserList";
    }

    @GetMapping("delAdminUser/{id}")
    @ApiOperation("删除管理员账户")
    public String delUser(@PathVariable("id") int id, Model model) {
        boolean flag = adminuserService.deleteById(id);
        if (flag) {
            model.addAttribute("msg", "删除成功！");
        } else {
            model.addAttribute("msg", "该用户不允许删除！");
        }
        return "forward:/admin/users/getUserList";
    }
}
